﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BabyFood.Entities;
using BabyFood.Data;

public partial class AnhDep : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request.QueryString["id"] != null)
            {
                H_IdBoSuuTap.Value = Request.QueryString["id"].ToString();
                BoSuuTap entBoSuuTap = DataRepository.BoSuuTapProvider.GetById(Convert.ToInt32(H_IdBoSuuTap.Value));
                
            }
            Pager1.CurrentIndex = 1;
            HienThialbumbe(Pager1.CurrentIndex);
            Pager2.CurrentIndex = 1;
            HienThialbumthoau(Pager2.CurrentIndex);
        }
        Session["Title"] = "Album Ảnh Đẹp";
    }
    /// <summary>
    /// Hien thi album be
    /// </summary>
    /// <param name="PageNo"></param>
    private void HienThialbumbe(int PageNo)
    {
        int TotalRows = 0;
        string tenalbum = "Album Ảnh của bé";
        string WhereClause = "1=1 and NhomAlbum like N'%" + Convert.ToString(tenalbum) + "%'";
        TList<BoSuuTap> dsAnhDep = DataRepository.BoSuuTapProvider.GetPaged(WhereClause, "NgayCapNhat DESC", PageNo - 1, Pager1.PageSize, out TotalRows);
        dlAnhDep.DataSource = dsAnhDep;
        dlAnhDep.DataBind();

        Pager1.ItemCount = TotalRows;
        H_PageCount.Value = Pager1.PageCount.ToString();
    }

    protected void Pager1_Command(object sender, CommandEventArgs e)
    {
        int currnetPageIndex = Convert.ToInt32(e.CommandArgument);
        Pager1.CurrentIndex = currnetPageIndex;
        HienThialbumbe(currnetPageIndex);
    }

    protected void cmdNext_Click(object sender, ImageClickEventArgs e)
    {
        if (Pager1.CurrentIndex < Convert.ToInt32(H_PageCount.Value))
        {
            Pager1.CurrentIndex = Pager1.CurrentIndex + 1;
            HienThialbumbe(Pager1.CurrentIndex);
        }
    }

    protected void cmdPrevious_Click(object sender, ImageClickEventArgs e)
    {
        if (Pager1.CurrentIndex > 1)
        {
            Pager1.CurrentIndex = Pager1.CurrentIndex - 1;
            HienThialbumbe(Pager1.CurrentIndex);
        }
    }

    /// <summary>
    /// Hien thi album thoi tho au
    /// </summary>
    /// <param name="PageNo"></param>
    private void HienThialbumthoau(int PageNo)
    {
        int TotalRows = 0;
        string tenalbum = "Album Ảnh thời ấu thơ";
        string WhereClause = "1=1 and NhomAlbum like N'%" + Convert.ToString(tenalbum) + "%'";
        TList<BoSuuTap> dsAnhDep = DataRepository.BoSuuTapProvider.GetPaged(WhereClause, "NgayCapNhat DESC", PageNo - 1, Pager2.PageSize, out TotalRows);
        dlthoau.DataSource = dsAnhDep;
        dlthoau.DataBind();

        Pager2.ItemCount = TotalRows;
        H_PageCount2.Value = Pager2.PageCount.ToString();
    }

    protected void Pager2_Command(object sender, CommandEventArgs e)
    {
        int currnetPageIndex = Convert.ToInt32(e.CommandArgument);
        Pager2.CurrentIndex = currnetPageIndex;
        HienThialbumthoau(currnetPageIndex);
    }

    protected void cmdNext_Click2(object sender, ImageClickEventArgs e)
    {
        if (Pager2.CurrentIndex < Convert.ToInt32(H_PageCount.Value))
        {
            Pager2.CurrentIndex = Pager2.CurrentIndex + 1;
            HienThialbumthoau(Pager2.CurrentIndex);
        }
    }

    protected void cmdPrevious_Click2(object sender, ImageClickEventArgs e)
    {
        if (Pager2.CurrentIndex > 1)
        {
            Pager2.CurrentIndex = Pager2.CurrentIndex - 1;
            HienThialbumthoau(Pager2.CurrentIndex);
        }
    }


    public string GetHinhAnhThumb(object Ten, object BST)
    {
        return Common.sPathUpBoSuuTap + "/" + BST + "/Thumb/" + Ten;
    }

    public string GetHinhAnhFull(object Ten, object BST)
    {
        return "Upload/BoSuuTap/" + BST + "/Full/" + Ten;
    }
    public string GetImageBoSuuTap(object IdBoSuuTap)
    {
        int TotalRows = 0;
        TList<HinhAnh> Tlist_HinhAnh = DataRepository.HinhAnhProvider.GetPaged("IdBoSuuTap='" + IdBoSuuTap + "'", "NgayCapNhat DESC", 0, 1, out TotalRows);
        return Tlist_HinhAnh.Count > 0 ? Common.sPathUpBoSuuTap + "/" + IdBoSuuTap + "/Thumb/" + Tlist_HinhAnh[0].AnhDaiDien : "~/Images/no_image.jpg";
    }

    public string GetTieuDe(object Char)
    {
        string s = Char.ToString();
        return Common.ConvertToUnSign(s);
    }
}